//
//  LXDSelectSingerViewController.m
//  BLDMusics
//
//  Created by lxd on 16/3/20.
//  Copyright © 2016年 李晓丹. All rights reserved.
//

#import "LXDSelectSingerViewController.h"

@interface LXDSelectSingerViewController ()<UITableViewDataSource, UITableViewDelegate>

@property (nonatomic, retain) UITableView *tableView;

/**
 *  源数据
 */
@property (nonatomic, retain) NSMutableArray *modelArr;

@property (nonatomic, strong) UIVisualEffectView *visualEfView; /**< 毛玻璃 */
@end

@implementation LXDSelectSingerViewController

- (void)viewWillAppear:(BOOL)animated {
    self.navigationController.navigationBar.translucent = NO;
    self.navigationController.navigationBar.barTintColor = [UIColor colorWithRed:95 / 255.0 green:217 / 255.0 blue:238 / 255.0 alpha:1];
}

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.

    [self crateTableView];
    [self dataHandle];
    
}

- (void)crateTableView {
    
    self.view.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"ground.jpg"]];
    // 毛玻璃
    self.visualEfView = [[UIVisualEffectView alloc] initWithEffect:[UIBlurEffect effectWithStyle:UIBlurEffectStyleLight]];
    _visualEfView.frame = CGRectMake(0, 0, self.view.bounds.size.width, self.view.bounds.size.height);
    _visualEfView.alpha = 0.8;
    _visualEfView.userInteractionEnabled = YES;
    [self.view addSubview:_visualEfView];
    
    self.modelArr = [NSMutableArray array];
    self.tableView = [[UITableView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, SCREEN_HEIGTH - 64 - 49) style:UITableViewStylePlain];
    _tableView.delegate =self;
    _tableView.dataSource = self;
    [self.view addSubview:_tableView];
    _tableView.backgroundColor = [UIColor clearColor];
    [_tableView registerClass:[LXDSelectSingerTableViewCell class] forCellReuseIdentifier:@"cell"];
    
}

#pragma mark - 协议方法
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return _modelArr.count;
}
#pragma mark 返回cell
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    LXDSelectSingerTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"cell"];
    LXDSingerModel *model = _modelArr[indexPath.row];
    cell.model = model;
    return cell;
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
    return 80;
}
#pragma 点击方法
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    LXDSongListViewController *vc = [[LXDSongListViewController alloc] init];
    LXDSingerModel *model = _modelArr[indexPath.row];
    vc.singer = model;
    [self.navigationController pushViewController:vc animated:YES];
}



#pragma mark - 数据解析
- (void)dataHandle {
    NSString *str = [NSString stringWithFormat:@"http://v1.ard.tj.itlily.com/ttpod?a=getnewttpod&id=%@", _ID];
    
    [APPTools GETWithURL:str par:nil success:^(id responseObject) {
        self.modelArr = [LXDSingerModel modelHandleWithArray:responseObject[@"data"]];
        [_tableView reloadData];
    } filed:^(NSError *error) {
        
    }];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
